package com.yc.yyds.dao;

import com.yc.yyds.util.DBHelper;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class QueryMoviesShowListDao {



    public List<Map<String,Object>> queryArrangeMovies(){
        String sql ="SELECT DISTINCT m.movieid,moviename,grade,type,movieimage,m.area,TIMESTAMPDIFF(MINUTE ,starttime,endtime)time from arrange a inner join movie m on a.movieid=m.movieid ";
        return DBHelper.selectListMap(sql);
    }

    //用户买票查询排片

    public List<Map<String,Object>> queryCinemaMovies(String id,String starttime){
        String sql = "select a.remainseats,a.ppjhid, m.Moviename,c.seats,c.cinemaname,c.cinemadesc ,a.sell,a.starttime,a.endtime,m.type,m.movieimage from movie m INNER JOIN arrange a " +
                "on m.movieid=a.movieid INNER JOIN cinema c " +
                "on a.cinemaid=c.cinemaid where 1=1";
        List<Object> params = new ArrayList<>();
        if (id !=null && !id.equals("")){
            sql+= " and m.movieid = ? ";
            params.add(id);
        }
        if (starttime!=null && !starttime.equals("")){
            sql+= " and a.starttime like ?";
            params.add("%"+starttime+"%");
        }
        return DBHelper.selectListMap(sql,params.toArray());
    }

    public List<Map<String,Object>> showMovies(){
        String sql ="select * from movie order BY insert_time desc LIMIT 0,5";
        return DBHelper.selectListMap(sql);
    }

    //查询排放放映时间
    public List<Map<String,Object>> queryTime(){
        String sql =" select DISTINCT DATE_FORMAT(starttime, '%Y-%m-%d')time from arrange where starttime >= NOW() ORDER BY starttime";
        return DBHelper.selectListMap(sql);
    }





}
